﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
</head>

<body>
    <script>
        var shuLiang = parseInt(prompt("请输入考试科目的数量"));
        var sum = 0;
        if (isNaN(shuLiang) == false && shuLiang > 0) {
            for (var i = 1; i <= shuLiang; i++) {
                var chengJi = parseInt(prompt("请输入第" + i + "门科目的成绩"));
                if (isNaN(chengJi) == false && chengJi >= 0) {
                    sum = sum + chengJi;
                    document.write("第" + i + "门课的成绩是：" + chengJi + "<br />");
                } else {
                    alert("请输入正确的科目成绩");
                    break;
                }
            }
            document.write(i + "门课的总成绩是:" + sum);

        } else {
            alert("请输入正确的考试科目数量");
        }
    </script>
</body>

</html>